<%@ page import="com.deepai.dprsmgr.utils.ErrCode" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@include file="../base_path.jsp" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-cache"/>
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="description" content="">

    <link rel="stylesheet" type="text/css" href="<%=basePath%>/lib/bootstrap/3.3.7/css/bootstrap.min.css"/>
    <link type="text/css" rel="stylesheet" href="<%=basePath%>/lib/bootstrap-select/css/bootstrap-select.min.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="<%=basePath%>/lib/lobibox/css/lobibox.min.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="<%=basePath%>/css/mycss.css"/>
	
    <title>创建组织</title>
	
	<style type="text/css">
		body {
			background: #FFF;
		}

		.control-label {
			text-align: right;
		}
	</style>
</head>
<body>
<div class="modal-header">
    <button id="btn_close" type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <h4 class="modal-title">创建组织</h4>
</div>
<div class="modal-body">
    <div class="container-fluid container-fluid-w" style="background: #FFF;width: 90%;margin-top: 20px;">
            <form id="form_org_create" class="form-horizontal" style="padding: 20px;">
                <div class="form-group">
                    <label for="txt_org_name_for_create" class="col-xs-3 control-label">
                        <label class="text-danger" style="margin-right: 5px">*</label>组织名称</label>
                    <div class="col-xs-8">
                        <input type="text" class="form-control input-sm" id="txt_org_name_for_create" name="txt_org_name_for_create" placeholder="只支持中文、字母、数字、下划线，且不能以下划线开头结尾" maxlength="60">
                        <span class="help-block"></span>
                        <%--<p class="text-warning"><em>123</em></p>--%>
                    </div>
                </div>
                <div class="form-group">
                    <label for="txt_org_comment_for_create" class="col-xs-3 control-label">
                        <label class="text-danger" style="margin-right: 5px"></label>描述</label>
                    <div class="col-xs-8">
                        <textarea placeholder="只支持中文、字母、数字、下划线、逗号、句号，最多输入80个字" type="text" class="form-control input-sm" id="txt_org_comment_for_create"  name="txt_org_comment_for_create" rows="3" maxlength="80"></textarea>
                        <span class="help-block"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label for="select_business_template_for_create" class="col-xs-3 control-label">
                        <label class="text-danger" style="margin-right: 5px">*</label>业务模板</label>
                    <div class="col-xs-8">
                        <select id="select_business_template_for_create" class="selectpicker form-control input-sm" multiple data-live-search="true"
                               name="select_business_template_for_create" data-live-search-placeholder="Search" data-actions-box="true">
                            <c:forEach var="item" items="${templateListForCreate}">
                                <option value="${item.id}">${item.templateName}</option>
                            </c:forEach>
                        </select>
                        <span class="help-block"></span>
                    </div>
                </div>
                <%--<div class="form-group hidden">--%>
                    <%--<label for="select_display_number" class="col-xs-3 control-label">--%>
                        <%--<label class="text-danger" style="margin-right: 5px">*</label>外显号码</label>--%>
                    <%--<div class="col-xs-9">--%>
                        <%--<select id="select_display_number" class="selectpicker form-control input-sm" multiple data-live-search="true"--%>
                               <%--name="select_display_number" data-live-search-placeholder="Search" data-actions-box="true">--%>
                            <%--<c:forEach var="item" items="${displayInfoList}">--%>
                                <%--<option value="${item.id}">${item.displayName}</option>--%>
                            <%--</c:forEach>--%>
                        <%--</select>--%>
                        <%--<span class="help-block"></span>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <%--<div class="form-group hidden">--%>
                    <%--<label for="txt_maximum_number" class="col-xs-3 control-label">--%>
                        <%--<label class="text-danger" style="margin-right: 5px">*</label>最大并发数</label>--%>
                    <%--<div class="col-xs-9">--%>
                        <%--<input type="text" class="form-control input-sm" id="txt_maximum_number" name="txt_maximum_number" onkeyup="value=value.replace(/[^\d]/g,'')">--%>
                        <%--<span class="help-block"></span>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <%--<div class="form-group hidden">--%>
                    <%--<div class="col-xs-offset-3 col-xs-9">--%>
                        <%--<p style="line-height: 30px;background-color: #ccc;text-align: center;">剩余可用并发数 <span id="maxNumber">${remainRobotCount}</span></p>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <div class="form-group  text-c">
                    <%--<div class="col-xs-offset-3 col-xs-9">--%>
                        <%--<c:choose>--%>
                            <%--<c:when test="${remainRobotCount > 0}">--%>
                                <button type="submit" class="btn btn-primary btn-sm btn-s">提交</button>
                            <%--</c:when>--%>
                            <%--<c:otherwise>--%>
                                <%--<button type="submit" class="btn btn-primary btn-sm btn-block  btn-s" disabled>提交</button>--%>
                            <%--</c:otherwise>--%>
                        <%--</c:choose>--%>

                    <%--</div>--%>
                </div>
            </form>
        </div>
</div>






<%--<script type="text/javascript" src="<%=basePath%>/lib/jquery/1.11.0/jquery-1.11.0.min.js"></script>--%>
<%--<script type="text/javascript" src="<%=basePath%>/lib/bootstrap/3.3.7/js/bootstrap.js"></script>--%>
<%--<script type="text/javascript" src="<%=basePath%>/lib/bootstrap-select/js/bootstrap-select.min.js"></script>--%>
<%--<script type="text/javascript" src="<%=basePath%>/lib/bootstrap-select/js/i18n/defaults-zh_CN.js"></script>--%>
<%--<script type="text/javascript" src="<%=basePath%>/lib/jquery.validation/1.14.0/jquery.validate_1.js"></script>--%>
<%--<script type="text/javascript" src="<%=basePath%>/lib/jquery.validation/1.14.0/validate-methods.js"></script>--%>
<%--<script type="text/javascript" src="<%=basePath%>/lib/lobibox/js/lobibox.min.js"></script>--%>
<%--<script type="text/javascript" src="<%=basePath%>/lib/lobibox/js/messageboxes.min.js"></script>--%>
<%--<script type="text/javascript" src="<%=basePath%>/lib/lobibox/js/notifications.min.js"></script>--%>
<script type="text/javascript" src="<%=basePath%>/lib/JQuery.md5.js"></script>
<%--<script type="text/javascript" src="<%=basePath%>/js/common.js"></script>--%>


<script type="text/javascript">
    $(function () {
//        var Maxlen=parseInt($("#maxNumber").html());
        // 对象及变量声明
        $("#select_business_template_for_create").prop("disabled", false);
        $("#select_business_template_for_create").selectpicker();
//        $("#select_display_number").prop("disabled", false);
        $("#select_display_number").selectpicker({
		    noneSelectedText: '请选择' //默认显示内容
	    });
//        $selectBusinessTemplate.selectpicker('refresh');
//        $selectBusinessTemplate.selectpicker('deselectAll');


        var $orgName = $("#txt_org_name_for_create");
        var $comment = $("#txt_org_comment_for_create");
        var $businessTemplate = $("#select_business_template_for_create");
//        var $displayNumber= $("#select_display_number");
//        var $maximumNumber = $("#txt_maximum_number");


        $("#form_org_create").validate({
            errorPlacement: function(error, element) {
                // Append error within linked label
                //console.log(element)
                $( element )
                    .closest("div.form-group")
                        .find("span.help-block")
                            .append( error );
            },
            errorElement: "p",
            rules: {
                txt_org_name_for_create: {
                    required: true,
                    isNameChinese:true,
                    remote:{
                        type:"POST",
                        url:"<%=basePath%>/account/getOrgByOrgName.do", //请求地址
                        data:{
                            orgName:function(){ return $("#txt_org_name_for_create").val(); }
                        },
                        dataType: "html",
                        dataFilter:function(data){
                            if(JSON.parse(data).errorCode == "2001"){
                                return false;
                            }else{
                                return true;
                            }
                        }
                     }
                },
                txt_org_comment_for_create:{
                    required: false,
					commentCheck:true,
					maxlength: 80,
                },
                select_business_template_for_create: {
                    required: true
                },
//                select_display_number: {
//                    required: false
//                },
//                txt_maximum_number:{
//                    required: true,
//                    isLtNum:Maxlen//动态获取
//                }
            },
            messages: {
                txt_org_name_for_create: {
					maxlength: "请输入不超过60个字符。",
                    required: "组织名称不能为空，请输入组织名称",
					isNameChinese: "字符或格式有误，只支持中文、字母、数字、下划线，且不能以下划线开发或结尾",
                    remote:"组织名已存在，请重新输入"
                },
                txt_org_comment_for_create:{
					commentCheck: "只支持中文、字母、数字、下划线、逗号、句号",
					maxlength: "请输入不超过80个字符。"
				},
                select_business_template_for_create: {
                    required: "业务模板不能为空，请选择"
                },
//                select_display_number: {
//                    required: "外显号码不能为空，请选择"
//                },
//                txt_maximum_number:{
//                    required: "最大并发数不能为空，请输入最大并发数",
//                    isLtNum:"输入数字不能超过最大并发数"//动态获取
//                }
            }
        });

        $('.selectpicker').on('hide.bs.select',function(e){
            $(this).focusout();
            if($(this).val() ==  null){
                $(this).addClass("has-error").siblings(".btn").addClass("redBorder");
            }else{
                $(this).removeClass("has-error").siblings(".btn").removeClass("redBorder");
            }
        });

        // 表单提交
        $("#form_org_create").submit(function (event) {
            var orgName = $.trim($orgName.val());
            var comment = $.trim($comment.val().trim());
            var businessTemplate = $businessTemplate.val();
//            var explicitNumber = $displayNumber.val();
//            var maximumNumber = $.trim($maximumNumber.val());

            if($(".form-control.error").size() == 0){
                // 这里用的是this，如果是Form的话需要Form[0]
                var formData = new FormData(this);
                formData.append("org_name", orgName);
                formData.append("comment", comment);
                formData.append("template_ids", businessTemplate);
                formData.append("displayIds", 0);
                formData.append("maxCallNumber", 0);
                // 阻止当前提交事件，自行实现，否则会跳转
                event.preventDefault();
                $.ajax({
                    url: '<%=basePath%>/account/orgCreate.do',
                    type: 'POST',
                    data: formData,
                    async: false,
                    // 这两个参数需要被定义，否则报错
                    contentType: false,
                    processData: false,
                    traditional: true,
                    success: function (data) {
                        if (data["errorCode"] == "<%=ErrCode.ERR_CODE_SUCCESS%>") {
                            myNotify("success", "", "组织创建成功！");
                            $("#modal_create_org").modal('hide');
                        } else {
                            myNotify("error", "", "组织创建失败！");
                        }
                    },
                    error: function () {
                        myNotify("error", "", "组织创建过程中发生错误，请联系管理员！");
                    }
                });
            }else{
                    myNotify("error", "", "请更正错误后在进行提交");
            }
            return false;
        });
    });
    /******************************方法声明**********************************/
    // 重置表单
    function resetForm() {
        $("#form_org_create")[0].reset();
        $('#select_business_template_for_create,#select_display_number').selectpicker('deselectAll');
    }

</script>

</body>
</html>